home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Graphics / Multimedia / Movie3.0 / Source / xanim / xanim_set.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-02  |  31.5 KB  |  1,189 lines

  1.  
  2. /*
  3.  * xanim_set.c
  4.  *
  5.  * Copyright (C) 1992,1993,1994 by Mark Podlipec.
  6.  * All rights reserved.
  7.  *
  8.  * This software may be freely copied, modified and redistributed without
  9.  * fee for non-commerical purposes provided that this copyright notice is
  10.  * preserved intact on all copies and modified copies.
  11.  *
  12.  * There is no warranty or other guarantee of fitness of this software.
  13.  * It is provided solely "as is". The author(s) disclaim(s) all
  14.  * responsibility and liability with respect to this software's usage
  15.  * or its effect upon hardware or computer systems.
  16.  *
  17.  */
  18. #include "xanim.h"
  19. #include "xanim_set.h"
  20. #include "xanim_iff.h"
  21. #include <ctype.h>
  22.  
  23. LONG Is_SET_File();
  24. ULONG SET_Read_File();
  25. SET_FRAM_HDR *SET_Init_FRAM_HDRS();
  26. UBYTE *SET_Read_BACK();
  27. UBYTE *SET_Read_FACE();
  28. SET_SSET_HDR *SET_Alloc_SSET_HDR();
  29. SET_SSET_HDR *SET_Get_SSET();
  30. SET_BACK_HDR *SET_Alloc_BACK_HDR();
  31. SET_BACK_HDR *SET_Get_BACK();
  32. SET_BACK_HDR *SET_Add_Black();
  33. void SET_TheEnd();
  34. void SET_TheEnd1();
  35. void SET_Extract_Directory();
  36. void SET_Modify_Directory();
  37. void SET_Read_SSET();
  38. void SET_Add_SETTER();
  39. void SET_Add_BACK();
  40. void SET_Add_TIME();
  41. void SET_Read_Sound_IFF();
  42. void SET_Add_CHDR();
  43. void SET_Free_Stuff();
  44.  
  45. ULONG UTIL_Get_MSB_Long();
  46. LONG UTIL_Get_MSB_Short();
  47. ULONG UTIL_Get_MSB_UShort();
  48. XA_ACTION *ACT_Get_Action();
  49. ULONG UTIL_Get_Buffer_Scale();
  50. void UTIL_Scale_Buffer_Pos();
  51. void ACT_Setup_Mapped();
  52. void IFF_Read_BMHD();
  53. void IFF_Read_BODY();
  54. void IFF_Read_CMAP_0();
  55. void IFF_Read_CMAP_1();
  56. void IFF_Shift_CMAP();
  57. void IFF_Print_ID();
  58.  
  59. XA_CHDR *ACT_Get_CMAP();
  60. ULONG CMAP_Get_Or_Mask();
  61. void ACT_Add_CHDR_To_Action();
  62.  
  63.  
  64. static ColorReg set_cmap[256];
  65. static XA_CHDR *set_chdr;
  66. static SET_BACK_HDR *set_back_start,*set_back_cur;
  67. static ULONG set_back_num,set_sset_num;
  68. static SET_FRAM_HDR *set_frames;
  69. static ULONG set_fram_num;
  70. static SET_SSET_HDR *set_sset_start,*set_sset_cur;
  71. static XA_ACTION *work_act;
  72. static XA_ACTION *back_act;
  73. static ULONG set_time;
  74. static LONG set_xscroll_flag,set_xscroll_len,set_yscroll_flag,set_yscroll_len;
  75. static LONG set_back_xpos,set_back_ypos;
  76. static ULONG set_back_scroll_fram;
  77. static LONG set_sset_cur_num,set_sset_xoff,set_sset_yoff;
  78. static ULONG set_multi_flag;
  79. static ULONG set_or_mask;
  80.  
  81. static char set_buff[512];
  82. static char set_buff1[64];
  83. static Bit_Map_Header bmhd;
  84.  
  85. static ULONG set_imagex,set_imagey,set_imagec,set_imaged;
  86.  
  87.  
  88. void SET_Print_CHID(chid)
  89. ULONG chid;
  90. {
  91.   ULONG d;
  92.   d = (chid >> 24) & 0xff; fputc(d,stderr);
  93.   d = (chid >> 16) & 0xff; fputc(d,stderr);
  94.   d = (chid >>  8) & 0xff; fputc(d,stderr);
  95.   d = chid  & 0xff;        fputc(d,stderr);
  96.   fputc(' ',stderr);
  97. }
  98.  
  99. SET_BACK_HDR *SET_Get_BACK(back_num)
  100. ULONG back_num;
  101. {
  102.   SET_BACK_HDR *tmp;
  103.  
  104.   tmp = set_back_start;
  105.   while(tmp)
  106.   {
  107.     if (tmp->num == back_num) return(tmp);
  108.     tmp = tmp->next;
  109.   }
  110.   fprintf(stderr,"SET_Get_BACK: invalid back_num %lx\n",back_num);
  111.   SET_TheEnd();
  112.   return(0);
  113. }
  114.  
  115. SET_BACK_HDR *SET_Add_Black(anim_hdr)
  116. XA_ANIM_HDR *anim_hdr;
  117. {
  118.   UBYTE *pic;
  119.   SET_BACK_HDR *tmp;
  120.   XA_ACTION *act;
  121.   ULONG psize;
  122.  
  123.     /* if black already exists */
  124.   if (set_back_start != 0)
  125.     if (set_back_start->num == 0xffff) return(set_back_start);
  126.  
  127.   psize = set_imagex * set_imagey;
  128.   if (work_act == 0)
  129.   {
  130.     UBYTE *t_pic;
  131.     t_pic = (UBYTE *)malloc( XA_PIC_SIZE(psize) );
  132.     if (t_pic == 0) SET_TheEnd1("SET a: malloc failed\n");
  133.     memset(t_pic, 0x00, psize );
  134.     act = ACT_Get_Action(anim_hdr);
  135.     ACT_Setup_Mapped(act,t_pic,set_chdr,0,0,set_imagex,set_imagey,
  136.     set_imagex,set_imagey,FALSE,0,TRUE,TRUE,FALSE);
  137.     work_act = act;
  138.   }
  139.  
  140.   tmp = (SET_BACK_HDR *)malloc( sizeof(SET_BACK_HDR) );
  141.   if (tmp == 0) SET_TheEnd1("SET: back malloc fail\n");
  142.  
  143.   tmp->num = 0xffff;
  144.   tmp->xsize = tmp->xscreen = set_imagex;
  145.   tmp->ysize = tmp->yscreen = set_imagey;
  146.   tmp->xpos = tmp->ypos = 0;
  147.   tmp->back_act = 0;
  148.   tmp->csize = 0;
  149.   tmp->chdr  = 0;
  150.   tmp->next = set_back_start;
  151.   set_back_start = tmp;
  152.  
  153.   pic = (UBYTE *)malloc( XA_PIC_SIZE(psize) );
  154.   if (pic == 0) SET_TheEnd1("SET_Add_Black: malloc failed\n");
  155.  
  156.   memset( pic, set_or_mask, psize );
  157.   act = ACT_Get_Action(anim_hdr);
  158.   tmp->back_act = act; 
  159.   ACT_Setup_Mapped(act,pic,set_chdr,0,0,set_imagex,set_imagey,
  160.     set_imagex,set_imagey,FALSE,0,TRUE,TRUE,FALSE);
  161.   return(set_back_start);
  162. }
  163.   
  164.  
  165. SET_BACK_HDR *SET_Alloc_BACK_HDR()
  166. {
  167.   SET_BACK_HDR *tmp;
  168.  
  169.   
  170.   tmp = (SET_BACK_HDR *)malloc( sizeof(SET_BACK_HDR) );
  171.   if (tmp == 0) SET_TheEnd1("SET: back malloc fail\n");
  172.  
  173.   tmp->num = set_back_num;
  174.   set_back_num++;
  175.   tmp->xsize = 0;   tmp->ysize = 0;
  176.   tmp->xscreen = 0; tmp->yscreen = 0;
  177.   tmp->xpos = 0;    tmp->ypos = 0;
  178.   tmp->back_act = 0;
  179.   tmp->csize = 0;
  180.   tmp->chdr = 0;
  181.   tmp->next = 0;
  182.  
  183.   if (set_back_start == 0) set_back_start = tmp;
  184.   else set_back_cur->next = tmp;
  185.   set_back_cur = tmp;
  186.   return(set_back_cur);
  187. }
  188.  
  189. SET_SSET_HDR *SET_Get_SSET(sset_num)
  190. ULONG sset_num;
  191. {
  192.   SET_SSET_HDR *tmp;
  193.  
  194.   tmp = set_sset_start;
  195.   while(tmp)
  196.   {
  197.     if (tmp->num == sset_num) return(tmp);
  198.     tmp = tmp->next;
  199.   }
  200.   fprintf(stderr,"SET_Get_SSET: invalid sset_num %lx\n",sset_num);
  201.   SET_TheEnd();
  202.   return(0);
  203. }
  204.  
  205. SET_SSET_HDR *SET_Alloc_SSET_HDR()
  206. {
  207.   SET_SSET_HDR *tmp;
  208.  
  209.   tmp = (SET_SSET_HDR *)malloc( sizeof(SET_SSET_HDR) );
  210.   if (tmp == 0) SET_TheEnd1("SET: set malloc fail\n");
  211.  
  212.   tmp->num = set_sset_num;
  213.   set_sset_num++;
  214.   tmp->faces = 0;
  215.   tmp->next = 0;
  216.   tmp->face_num = 0;
  217.  
  218.   if (set_sset_start == 0) set_sset_start = tmp;
  219.   else set_sset_cur->next = tmp;
  220.   set_sset_cur = tmp;
  221.   return(set_sset_cur);
  222. }
  223.  
  224. /*
  225.  *
  226.  */
  227. LONG Is_SET_File(filename)
  228. char *filename;
  229. {
  230.   FILE *fin;
  231.   ULONG d1,d2;
  232.  
  233.   if ( (fin=fopen(filename,XA_OPEN_MODE)) == 0) return(XA_NOFILE);
  234.  
  235.   d1 = UTIL_Get_MSB_Long(fin);  /* read past size */
  236.   d2 = UTIL_Get_MSB_Long(fin); /* read magic */
  237.   fclose(fin);
  238.   /* check for "xSceneEd"itor */
  239.   if ( (d1 == 0x78536365) && (d2 == 0x6e654564) )return(TRUE);
  240.   /* check for "xMovieSe"tter */
  241.   if ( (d1 == 0x784d6f76) && (d2 == 0x69655365) )return(TRUE);
  242.   return(FALSE);
  243. }
  244.  
  245. ULONG SET_Read_File(fname,anim_hdr)
  246. char *fname;
  247. XA_ANIM_HDR *anim_hdr;
  248. {
  249.   FILE *fin;
  250.   ULONG op; 
  251.   ULONG cur_fram_num;
  252.   ULONG cur_fram_cnt;
  253.   ULONG exit_flag;
  254.  
  255.   set_multi_flag = TRUE;
  256.   cur_fram_num   = 0;
  257.   cur_fram_cnt   = 0;
  258.   work_act    = 0;
  259.   back_act    = 0;
  260.   set_fram_num   = 0;
  261.   set_frames     = (SET_FRAM_HDR *)0;
  262.   set_back_start = 0;
  263.   set_back_cur   = 0;
  264.   set_back_num   = 0;
  265.   set_sset_start = 0;
  266.   set_sset_cur   = 0;
  267.   set_sset_num   = 0;
  268.   set_xscroll_flag = 0;
  269.   set_xscroll_len = 0;
  270.   set_yscroll_flag = 0;
  271.   set_yscroll_len = 0;
  272.   set_back_xpos = 0;
  273.   set_back_ypos = 0;
  274.   set_back_scroll_fram = 1;
  275.   /* default stuff if no background */
  276.   set_imagex = 352;
  277.   set_imagey = 240;
  278.   set_imaged = 5;
  279.   bmhd.compression = BMHD_COMP_BYTERUN;
  280.   bmhd.masking = BMHD_MSK_NONE;
  281.  
  282.   set_or_mask = CMAP_Get_Or_Mask(1 << set_imaged);
  283.  
  284.   if ( (fin=fopen(fname,XA_OPEN_MODE)) == 0)
  285.   {
  286.     fprintf(stderr,"Can't open SET File %s for reading\n",fname);
  287.     return(FALSE);
  288.   }
  289.  
  290.   DEBUG_LEVEL1 fprintf(stderr,"Reading SET file %s:\n",fname);
  291.   exit_flag = 0;
  292.   while(!feof(fin) && !exit_flag)
  293.   {
  294.    XA_ACTION *act;
  295.  
  296.     op = fgetc(fin);
  297.  
  298.     switch(op)
  299.     {
  300.      case 'a':  /* 256 ascii 32 ascii IFF stuff  Background Image */
  301.     {
  302.       SET_BACK_HDR *tmp_back_hdr;
  303.       UBYTE *pic;
  304.       fread((char *)set_buff,1,256,fin); set_buff[256] = 0;
  305.       DEBUG_LEVEL1 fprintf(stderr," a) %s    ",set_buff);
  306.       fread((char *)set_buff1,1,32,fin); set_buff1[32] = 0;
  307.       DEBUG_LEVEL1 fprintf(stderr,"   %s\n",set_buff1);
  308.       tmp_back_hdr = SET_Alloc_BACK_HDR();
  309.       if (set_multi_flag == FALSE)
  310.           pic = SET_Read_BACK(fin,tmp_back_hdr);
  311.       else
  312.       {
  313.         FILE *fnew;
  314.         SET_Extract_Directory(set_buff,set_buff1);
  315.         if ( (fnew=fopen(set_buff,XA_OPEN_MODE)) == 0)
  316.         {
  317.           SET_Modify_Directory(set_buff,0);
  318.           if ( (fnew=fopen(set_buff,XA_OPEN_MODE)) == 0)
  319.           {
  320.             fprintf(stderr,"Can't open SET File %s for reading\n",set_buff);
  321.             SET_TheEnd();
  322.           }
  323.         }
  324.         pic = SET_Read_BACK(fnew,tmp_back_hdr);
  325.         fclose(fnew);
  326.       }
  327.       if (pic == 0) SET_TheEnd1("SET read a) failed");
  328.       if (work_act == 0)
  329.       {
  330.         UBYTE *t_pic;
  331.         t_pic = (UBYTE *) malloc( 
  332.         XA_PIC_SIZE(tmp_back_hdr->xsize * tmp_back_hdr->ysize) );
  333.         if (t_pic == 0) SET_TheEnd1("SET a: malloc failed\n");
  334.         memset(t_pic, 0x00, (tmp_back_hdr->xsize * tmp_back_hdr->ysize) ); 
  335.         act = ACT_Get_Action(anim_hdr);
  336.         ACT_Setup_Mapped(act,t_pic,set_chdr,
  337.         0,0,tmp_back_hdr->xsize,tmp_back_hdr->ysize,
  338.             set_imagex,set_imagey,FALSE,0,TRUE,FALSE,FALSE);
  339.             ACT_Add_CHDR_To_Action(act,tmp_back_hdr->chdr);
  340.         work_act = act;
  341.       }
  342.       act = ACT_Get_Action(anim_hdr);
  343.       tmp_back_hdr->back_act = act;
  344.       ACT_Setup_Mapped(act,pic,set_chdr,
  345.         0,0,tmp_back_hdr->xsize,tmp_back_hdr->ysize,
  346.             set_imagex,set_imagey,FALSE,0,TRUE,FALSE,FALSE);
  347.           ACT_Add_CHDR_To_Action(act,set_chdr);
  348.     }
  349.     break;
  350.      case 'b':  /* 256 ascii 32 ascii IFF stuff  Faces */
  351.     {
  352.       SET_SSET_HDR *tmp_sset_hdr;
  353.       tmp_sset_hdr = SET_Alloc_SSET_HDR();
  354.       fread((char *)set_buff,1,256,fin); /* disk:directory name */
  355.       set_buff[256] = 0;
  356.       DEBUG_LEVEL1 fprintf(stderr," b) %s    ",set_buff);
  357.       fread((char *)set_buff1,1,32,fin); /* file name */
  358.       set_buff1[32] = 0;
  359.       DEBUG_LEVEL1 fprintf(stderr,"   %s\n",set_buff1);
  360.           if (set_multi_flag == FALSE) SET_Read_SSET(anim_hdr,fin,tmp_sset_hdr);
  361.           else
  362.           {
  363.  
  364.             FILE *fnew;
  365.             SET_Extract_Directory(set_buff,set_buff1);
  366.             if ( (fnew=fopen(set_buff,XA_OPEN_MODE)) == 0)
  367.             {
  368.           SET_Modify_Directory(set_buff,0);
  369.           if ( (fnew=fopen(set_buff,XA_OPEN_MODE)) == 0)
  370.           {
  371.         fprintf(stderr,"Can't open SET File %s for reading\n",set_buff);
  372.         SET_TheEnd();
  373.           }
  374.             }
  375.         SET_Read_SSET(anim_hdr,fnew,tmp_sset_hdr);
  376.             fclose(fnew);
  377.       }
  378.     }
  379.     break;
  380.      case 'c': /* 10 bytes set current frame */
  381.     {
  382.       ULONG i;
  383.       i = 8; while(i--) fgetc(fin);
  384.       cur_fram_num  = UTIL_Get_MSB_UShort(fin);
  385.       cur_fram_cnt = cur_fram_num;
  386.       DEBUG_LEVEL2 fprintf(stderr," c) %lx\n",cur_fram_num);
  387.     }
  388.     break;
  389.      case 'd': /* new SSET header 32 ascii + 10 bytes */
  390.     {
  391.       ULONG i;
  392.       fread((char *)set_buff,1,32,fin);
  393.       set_buff[32] = 0;
  394.       DEBUG_LEVEL1 fprintf(stderr," d) sset hdr %s  ",set_buff);
  395.       set_sset_cur_num = UTIL_Get_MSB_UShort(fin);
  396.       set_sset_xoff = UTIL_Get_MSB_Short(fin);
  397.       set_sset_yoff = UTIL_Get_MSB_Short(fin);
  398.       i = UTIL_Get_MSB_Short(fin);
  399.       i = UTIL_Get_MSB_Short(fin); /* last fram in series */
  400.       set_sset_cur = SET_Get_SSET(set_sset_cur_num);
  401.       DEBUG_LEVEL2 fprintf(stderr,"  %lx %lx\n",
  402.         set_sset_cur_num,set_sset_cur->num);
  403.       cur_fram_cnt = cur_fram_num;
  404.     }
  405.     break;
  406.      case 'e': /* position face 12 bytes */
  407.     {
  408.       SET_FACE_HDR *face_hdr;
  409.       ULONG face_num,depth,garb,fram_num;
  410.       LONG xpos,ypos,xoff,yoff;
  411.       LONG back_x,back_y;
  412.  
  413.       face_num = UTIL_Get_MSB_UShort(fin);
  414.       xoff     = UTIL_Get_MSB_Short(fin);
  415.       yoff     = UTIL_Get_MSB_Short(fin);
  416.       depth    = UTIL_Get_MSB_UShort(fin);
  417.       garb     = UTIL_Get_MSB_UShort(fin);
  418.       fram_num = UTIL_Get_MSB_UShort(fin); /* not correct */
  419.       DEBUG_LEVEL2 fprintf(stderr," e) %lx (%lx %x) %lx %lx %lx\n",
  420.         face_num,xoff,yoff,depth,garb,fram_num);
  421.       if (face_num > set_sset_cur->face_num)
  422.       {
  423.         fprintf(stderr,"SET_Read: e) face_num invalid %lx (%lx)",
  424.         face_num, set_sset_cur->face_num);
  425.         SET_TheEnd();
  426.       }
  427.       face_hdr = &(set_sset_cur->faces[face_num]);
  428.  
  429.       xpos  = face_hdr->xoff + set_sset_xoff;
  430.       xpos += xoff;
  431.       ypos  = face_hdr->yoff + set_sset_yoff;
  432.       ypos += yoff;
  433. DEBUG_LEVEL2 fprintf(stderr,"      e FACE off <%ld,%ld> fin <%ld,%ld>\n",
  434.         xoff,yoff,xpos,ypos);
  435.  
  436.  
  437.       /* Back ground Scrolling calculations - see g) */
  438.       if (set_xscroll_flag == 1)
  439.       {
  440.         back_x = -set_xscroll_len * (cur_fram_cnt - set_back_scroll_fram);
  441.         while(back_x < 0) back_x += set_back_cur->xsize;
  442.         if (back_x >= set_back_cur->xsize) back_x %= set_back_cur->xsize;
  443.       } else back_x = 0;
  444.  
  445.       if (set_yscroll_flag == 1)
  446.       {
  447.         back_y = -set_yscroll_len * (cur_fram_cnt - set_back_scroll_fram);
  448.         while(back_y < 0) back_y += set_back_cur->ysize;
  449.         if (back_y >= set_back_cur->ysize) back_y %= set_back_cur->ysize;
  450.       } else back_y = 0;
  451.  
  452.           if (face_hdr->face_act->type != ACT_NOP)
  453.         SET_Add_SETTER(anim_hdr,cur_fram_cnt,back_x,back_y,
  454.           xpos,ypos,face_hdr->face_act,depth);
  455.       cur_fram_cnt++;
  456.     }
  457.     break;
  458.      case 'f': /* backgrnd display info  4 bytes */
  459.     {
  460.       ULONG back,effect;
  461.       back = UTIL_Get_MSB_UShort(fin);
  462.       effect = UTIL_Get_MSB_UShort(fin);
  463.       DEBUG_LEVEL2 
  464.          fprintf(stderr," f) backgrnd info %lx %lx  ",back,effect);
  465.       if (back == 0xffff) set_back_cur = SET_Add_Black(anim_hdr);
  466.       else set_back_cur = SET_Get_BACK(back);
  467.       DEBUG_LEVEL2 fprintf(stderr,"  %lx\n",set_back_cur->num);
  468.       SET_Add_BACK(cur_fram_num,set_back_cur->back_act,set_back_cur->chdr);
  469.     }
  470.     break;
  471.      case 'g': /* backgrnd scrolling info(?)  8 bytes */
  472.     {
  473.       LONG tmp1,tmp2,tmp3,tmp4;
  474.  
  475.       tmp1 = UTIL_Get_MSB_Short(fin);
  476.       tmp2 = UTIL_Get_MSB_Short(fin);
  477.       tmp3 = UTIL_Get_MSB_Short(fin);
  478.       tmp4 = UTIL_Get_MSB_Short(fin);
  479.  
  480.       if (tmp4 == 0)
  481.       { /* scroll only in x direction */
  482.         set_xscroll_flag = 1;
  483.         set_yscroll_flag = 0;
  484.         set_yscroll_len = 0;
  485.         if (tmp3 == 0) set_xscroll_len = tmp1;
  486.         else set_xscroll_len = tmp2;
  487.         if (set_xscroll_len == 0) set_xscroll_flag = 0;
  488.       }
  489.       else
  490.       { /* scroll only in y direction */
  491.         set_yscroll_flag = 1;
  492.         set_xscroll_flag = 0;
  493.         set_xscroll_len = 0;
  494.         if (tmp3 == 0) set_yscroll_len = tmp1;
  495.         else set_yscroll_len = tmp2; 
  496.         /* PODNOTE: I haven't seen tmp3 == tmp4 == 1 so this is a guess */
  497.         if (set_yscroll_len == 0) set_yscroll_flag = 0;
  498.       }
  499.       set_back_scroll_fram = cur_fram_num;
  500.       DEBUG_LEVEL2 fprintf(stderr," g) %ld %ld %ld %ld\n",
  501.          set_xscroll_flag,set_xscroll_len,set_yscroll_flag,set_yscroll_len);
  502.     }
  503.     break;
  504.      case 'h': /* sound info  10 bytes */
  505.     {
  506.       ULONG i;
  507.       DEBUG_LEVEL2 fprintf(stderr," h) sound info - not supported\n");
  508.       i = 10; while(i--) fgetc(fin);
  509.     }
  510.     break;
  511.      case 'i': /* timing info  2 bytes*/
  512.     set_time = UTIL_Get_MSB_UShort(fin); if (set_time == 0) set_time = 1;
  513.     DEBUG_LEVEL2 fprintf(stderr," i) %lx\n",set_time);
  514.     set_time = set_time * 16;
  515.         SET_Add_TIME(cur_fram_num,set_time);
  516.     break;
  517.      case 'j':  /* 256 ascii 32 ascii IFF stuff  Sounds Info */
  518.     fread((char *)set_buff,1,256,fin); set_buff[256] = 0;
  519.     DEBUG_LEVEL1 fprintf(stderr," j) %s    ",set_buff);
  520.     fread((char *)set_buff1,1,32,fin); set_buff1[32] = 0;
  521.     DEBUG_LEVEL1 fprintf(stderr,"   %s\n",set_buff1);
  522.         if (set_multi_flag == FALSE) SET_Read_Sound_IFF(fin);
  523.     /* else ignore */
  524.     break;
  525.      case 'k': /* ? header of some sort 40 bytes */
  526.     {
  527.       ULONG i;
  528.       DEBUG_LEVEL2 fprintf(stderr," k) ???\n");
  529.       i = 40; while(i--) fgetc(fin);
  530.     }
  531.     break;
  532.      case 'l': /* cmap info 64 bytes */
  533.     DEBUG_LEVEL2 fprintf(stderr," l) cmap\n");
  534.     set_imagec = 32;
  535.     IFF_Read_CMAP_1(set_cmap,set_imagec,fin);
  536.     IFF_Shift_CMAP(set_cmap,set_imagec);
  537.     set_chdr = ACT_Get_CMAP(set_cmap,set_imagec,set_or_mask,
  538.                 set_imagec,set_or_mask,4,4,4);
  539.     SET_Add_CHDR(set_chdr,cur_fram_num);
  540.     break;
  541.      case 'v': /* ? header of some sort 26 bytes */
  542.     {
  543.       ULONG i;
  544.       DEBUG_LEVEL2 fprintf(stderr," v) ?header?\n");
  545.       i = 26; while(i--) fgetc(fin);
  546.     }
  547.     break;
  548.      case 'w': /* frame count */
  549.     set_fram_num = UTIL_Get_MSB_UShort(fin)+1;
  550.         set_frames = SET_Init_FRAM_HDRS(set_fram_num);
  551.     DEBUG_LEVEL1 fprintf(stderr," w) %ld frames\n",set_fram_num);
  552.     break;
  553.      case 'x': /* title and version 32 ascii*/
  554.     fread((char *)set_buff1,1,32,fin); set_buff1[32] = 0;
  555.     DEBUG_LEVEL1 fprintf(stderr," x) %s\n",set_buff1);
  556.     break;
  557.      case 'y': /*  8 bytes  if present indicates IFF chunks included  */
  558.     DEBUG_LEVEL2 fprintf(stderr," y)\n");
  559.     set_multi_flag = FALSE;
  560.     break;
  561.      case 'z': /* EOF marker */
  562.     exit_flag = 1;
  563.     break;
  564.  
  565.  
  566.     default: fprintf(stderr,"Unknown opcode = %lx\n",op);
  567.         fclose(fin);
  568.     SET_TheEnd();
  569.    } /* end of switch */
  570.  } /* end of while */
  571.  fclose(fin);
  572.  
  573.  {
  574.    ULONG frame_cnt,i,j;
  575.    XA_ACTION *back_act;
  576.    ULONG fram_time;
  577.    ULONG buffx,buffy,need_to_scale;
  578.  
  579.    /* Check Out For buffer Scaling */
  580.    need_to_scale = UTIL_Get_Buffer_Scale(set_imagex,set_imagey,&buffx,&buffy);
  581.  
  582.    fram_time = 1;
  583.    frame_cnt = 0;
  584.    back_act = 0;
  585.    for(i=0; i<set_fram_num; i++)
  586.    {
  587.      SET_FRAM_HDR *fram_hdr;
  588.      ACT_SETTER_HDR *pms_hdr;
  589.  
  590.      fram_hdr = &(set_frames[i]);
  591.      frame_cnt++;
  592.      /* register chdr's */
  593.      if (fram_hdr->cm_hdr == 0) fram_hdr->cm_hdr = set_chdr;
  594.      else set_chdr = fram_hdr->cm_hdr;
  595.  
  596.      /* spread out timing info */
  597.      if (fram_hdr->time == 0xffffffff)
  598.        fram_hdr->time = fram_time;
  599.      else
  600.        fram_time = fram_hdr->time;
  601.  
  602.      /* spread out backgrounds */
  603.      if (fram_hdr->back_act != 0) back_act = fram_hdr->back_act;
  604.      else 
  605.        if (back_act != 0) fram_hdr->back_act = back_act;
  606.        else 
  607.        { 
  608.          set_back_cur = SET_Add_Black(anim_hdr);
  609.          back_act = set_back_cur->back_act;
  610.          fram_hdr->back_act = back_act;
  611.        }
  612.  
  613.      if (back_act->chdr == 0) ACT_Add_CHDR_To_Action(back_act,set_chdr);
  614.  
  615.     /* add set_chdr to setter action if it doesn't have one */
  616.      if (fram_hdr->pms_act) 
  617.      {
  618.        if (fram_hdr->pms_act->chdr == 0)
  619.         ACT_Add_CHDR_To_Action(fram_hdr->pms_act,set_chdr);
  620.      }
  621.      pms_hdr = fram_hdr->pms_hdr;
  622.      while(pms_hdr)
  623.      {
  624.        ACT_MAPPED_HDR *back_map_hdr;
  625.        back_map_hdr = (ACT_MAPPED_HDR *)back_act->data;
  626.        pms_hdr->back = back_act;
  627.        pms_hdr->xback = back_map_hdr->xsize;
  628.        pms_hdr->yback = back_map_hdr->ysize;
  629. DEBUG_LEVEL1
  630. {
  631.   fprintf(stderr,"---> %ld %ld   ",pms_hdr->xpback,pms_hdr->ypback);
  632.   if (pms_hdr->face) fprintf(stderr,"%ld %ld\n",pms_hdr->xpface,pms_hdr->ypface);
  633.   else fprintf(stderr,"\n");
  634. }
  635.        if (need_to_scale)
  636.         UTIL_Scale_Buffer_Pos(&pms_hdr->xpback,&pms_hdr->ypback,
  637.             set_imagex,set_imagey,buffx,buffy);
  638.     /* add set_chdr to face action if it doesn't have one */
  639.        if (pms_hdr->face)
  640.        {
  641.      if (pms_hdr->face->chdr == 0)
  642.         ACT_Add_CHDR_To_Action(pms_hdr->face,set_chdr);
  643.          if (need_to_scale)
  644.         UTIL_Scale_Buffer_Pos(&pms_hdr->xpface,&pms_hdr->ypface,
  645.             set_imagex,set_imagey,buffx,buffy);
  646.        }
  647. DEBUG_LEVEL1
  648. {
  649.   fprintf(stderr,"     %ld %ld   ",pms_hdr->xpback,pms_hdr->ypback);
  650.   if (pms_hdr->face) 
  651.     fprintf(stderr,"%ld %ld\n",pms_hdr->xpface,pms_hdr->ypface);
  652.   else fprintf(stderr,"\n");
  653. }
  654.        pms_hdr = pms_hdr->next;
  655.      }
  656.    } /* end of frame list loop */
  657.    frame_cnt++; /* last frame */ 
  658.    anim_hdr->frame_lst = (XA_FRAME *)malloc(sizeof(XA_FRAME) * frame_cnt);
  659.    if (anim_hdr->frame_lst == NULL)
  660.        TheEnd1("SET_ANIM: frame_lst malloc err");
  661.    anim_hdr->frame_lst[frame_cnt-1].time = 0;
  662.    anim_hdr->frame_lst[frame_cnt-1].act  = 0;
  663.  
  664.    j = 0;
  665.    for(i=0; i<set_fram_num; i++)
  666.    {
  667.      if (set_frames[i].pms_hdr != 0)
  668.      {
  669.        anim_hdr->frame_lst[j].time = set_frames[i].time;
  670.        anim_hdr->frame_lst[j].act  = set_frames[i].pms_act;
  671.        j++;
  672.      }
  673.      else
  674.      {
  675.        anim_hdr->frame_lst[j].time = set_frames[i].time;
  676.        anim_hdr->frame_lst[j].act  = set_frames[i].back_act;
  677.        j++;
  678.      }
  679.  
  680.    }
  681.    anim_hdr->loop_frame = 0;
  682.    anim_hdr->last_frame = frame_cnt-2;
  683.    anim_hdr->imagex = set_imagex;
  684.    anim_hdr->imagey = set_imagey;
  685.    anim_hdr->imagec = set_imagec;
  686.    anim_hdr->imaged = set_imaged;
  687.  
  688.  }
  689.  SET_Free_Stuff();
  690.  return(TRUE);
  691. }
  692.  
  693. UBYTE *SET_Read_BACK(fin,back_hdr)
  694. FILE *fin;
  695. SET_BACK_HDR *back_hdr;
  696. {
  697.   ULONG chid,data;
  698.   LONG size,form_size;
  699.   UBYTE *pic;
  700.  
  701.   pic = 0;
  702.   chid = UTIL_Get_MSB_Long(fin);
  703.   /* NOTE: for whatever reason the Anti-Lemmin' animation as a "bad" form 
  704.    * size with the upper 16 bits set to 0xffff. By making sure the last
  705.    * bit is clear, things should work ok anyways. We just read to the BODY.
  706.    */
  707.   form_size = UTIL_Get_MSB_Long(fin);
  708.   form_size &= 0x7fffffff;  /* PODNOTE: Anti-Lemmin' kludge/workaround */
  709.   data = UTIL_Get_MSB_Long(fin); form_size -= 4;
  710.   DEBUG_LEVEL1 fprintf(stderr,"SET_Read_BACK: chid %lx fsize %lx dat %lx\n", chid,form_size,data);
  711.   if (chid != FORM) SET_TheEnd1("SET: back is not FORM\n");
  712.   while(form_size)
  713.   {
  714.     chid = UTIL_Get_MSB_Long(fin); form_size -= 4;
  715.     size = UTIL_Get_MSB_Long(fin); form_size -= 4;
  716.     size &= 0x0000ffff;   /* PODNOTE: Anti-Lemmin' kludge/workaround */
  717.     form_size -= size;
  718.     if (form_size < 0) form_size = 0;
  719.  
  720.     DEBUG_LEVEL2 IFF_Print_ID(stderr,chid);
  721.     DEBUG_LEVEL2 fprintf(stderr," size %lx ",size);
  722.     switch(chid)
  723.     {
  724.       case BMHD:
  725.     IFF_Read_BMHD(fin,&bmhd);
  726.     set_imagex = bmhd.width;  /*pageWidth;*/
  727.     set_imagey = bmhd.height; /*pageHeight;*/
  728.     set_imaged = bmhd.depth;
  729.     back_hdr->xsize = bmhd.width;
  730.     back_hdr->ysize = bmhd.height;
  731.     back_hdr->xscreen = bmhd.width; /*pageWidth; */
  732.     back_hdr->yscreen = bmhd.height; /*pageHeight; */
  733.     DEBUG_LEVEL1 fprintf(stderr,"    %ldx%ldx%ld %ldx%ld cmp=%ld msk=%ld\n",
  734.         back_hdr->xsize,back_hdr->ysize,
  735.             set_imaged,back_hdr->xscreen,back_hdr->yscreen,
  736.         bmhd.compression, bmhd.masking);
  737.     break;
  738.       case CMAP:
  739.     set_imagec = size/3;
  740.     back_hdr->csize = set_imagec;
  741.     IFF_Read_CMAP_0(set_cmap,set_imagec,fin);
  742.     IFF_Shift_CMAP(set_cmap,set_imagec);
  743.     set_chdr = ACT_Get_CMAP(set_cmap,set_imagec,set_or_mask,
  744.                 set_imagec,set_or_mask,4,4,4);
  745.     back_hdr->chdr = set_chdr;
  746.     break;
  747.       case CAMG: /* ignore for now */
  748.       case CRNG: /* ignore for now */
  749.       case DPPS: /* ignore for now */
  750.       case DPPV: /* ignore for now */
  751.     {
  752.       ULONG d;
  753.           while( (size--) && !feof(fin) ) d = fgetc(fin);
  754.     }
  755.         break;
  756.       case BODY:
  757.     {
  758.       ULONG xsize,ysize;
  759.       xsize = bmhd.width;
  760.       ysize = bmhd.height;
  761.       pic = (UBYTE *) malloc( XA_PIC_SIZE(xsize * ysize) );
  762.       if (pic == 0) SET_TheEnd1("SET_Read_BODY: malloc failed\n");
  763.       IFF_Read_BODY(fin,pic,size, xsize, ysize, (ULONG)(bmhd.depth),
  764.         (int)(bmhd.compression), (int)(bmhd.masking),set_or_mask);
  765.       form_size = 0; /* body is always last */
  766.       break;
  767.     }
  768.       default: 
  769.     SET_Print_CHID(chid); SET_TheEnd1("\nUnknown in Back chunk\n");
  770.     break;
  771.     } /* end of switch */
  772.   } /* end of while */
  773.   return(pic);
  774. }
  775.  
  776.  
  777. void SET_Read_SSET(anim_hdr,fin,set_hdr)
  778. XA_ANIM_HDR *anim_hdr;
  779. FILE *fin;
  780. SET_SSET_HDR *set_hdr;
  781. {
  782.   ULONG chid,data;
  783.   LONG list_num,type,i;
  784.  
  785.   chid = UTIL_Get_MSB_Long(fin);
  786.   list_num = UTIL_Get_MSB_Long(fin) + 1;
  787.   data = UTIL_Get_MSB_Long(fin);
  788.   set_hdr->face_num = list_num;
  789.   DEBUG_LEVEL1 
  790.   {
  791.     fprintf(stderr,"    ");
  792.     SET_Print_CHID(chid);
  793.     fprintf(stderr,"%lx ",list_num);
  794.     SET_Print_CHID(data);
  795.     fprintf(stderr,"\n");
  796.   }
  797.   if (chid != LIST) SET_TheEnd1("SET: LIST not 1st in SSET\n");
  798.  
  799.   set_hdr->faces = (SET_FACE_HDR *)malloc(list_num * sizeof(SET_FACE_HDR) );
  800.   if (set_hdr->faces == 0) SET_TheEnd1("SET: faces malloc failed\n");
  801.  
  802.   /* Read PROP */
  803.   chid = UTIL_Get_MSB_Long(fin);  /* PROP */
  804.   DEBUG_LEVEL1 fprintf(stderr,"    ");
  805.   DEBUG_LEVEL1 SET_Print_CHID(chid);
  806.   if (chid != PROP) SET_TheEnd1("SET: 1st not PROP in SET\n");
  807.   data = UTIL_Get_MSB_Long(fin);  /* prop size */
  808.   type = UTIL_Get_MSB_Long(fin);  /* prop type */
  809.   DEBUG_LEVEL1 fprintf(stderr,"%lx ",data);
  810.   DEBUG_LEVEL1 SET_Print_CHID(type);
  811.  
  812.   /* Read CMAP */
  813.   chid = UTIL_Get_MSB_Long(fin);  /* CMAP */
  814.   DEBUG_LEVEL1 SET_Print_CHID(chid);
  815.   if (chid != CMAP) SET_TheEnd1("SET: 2st not CMAP in SET\n");
  816.   set_imagec = UTIL_Get_MSB_Long(fin);  /* CMAP size */
  817.   set_imagec /= 2;
  818.   DEBUG_LEVEL1 fprintf(stderr," %lx\n",set_imagec);
  819.   IFF_Read_CMAP_1(set_cmap,set_imagec,fin);
  820.   IFF_Shift_CMAP(set_cmap,set_imagec);
  821.   set_chdr = ACT_Get_CMAP(set_cmap,set_imagec,set_or_mask,
  822.                 set_imagec,set_or_mask,4,4,4);
  823.   
  824.   for(i = 1; i < list_num; i++)
  825.   {
  826.     SET_FACE_HDR *face;
  827.     UBYTE *pic;
  828.     XA_ACTION *act;
  829.  
  830.     face = &set_hdr->faces[i];
  831.     pic = SET_Read_FACE(fin,face);
  832.     if (pic==0) SET_TheEnd1("SET_Read_SSET: read face failed\n");
  833.  
  834.     act = ACT_Get_Action(anim_hdr);
  835.     ACT_Setup_Mapped(act,pic,set_chdr,
  836.     face->x,face->y,face->xsize,face->ysize,
  837.     set_imagex,set_imagey,TRUE,set_or_mask,TRUE,FALSE,FALSE);
  838.     ACT_Add_CHDR_To_Action(act,set_chdr);
  839.     face->face_act = act;
  840.   }
  841. }
  842.  
  843.  
  844. UBYTE *SET_Read_FACE(fin,face_hdr)
  845. FILE *fin;
  846. SET_FACE_HDR *face_hdr;
  847. {
  848.   ULONG chid,data;
  849.   LONG size,form_size;
  850.   UBYTE *pic;
  851.  
  852.   pic = 0;
  853.   face_hdr->xsize = 0;
  854.   face_hdr->ysize = 0;
  855.   chid = UTIL_Get_MSB_Long(fin);
  856.   form_size = UTIL_Get_MSB_Long(fin);
  857.   data = UTIL_Get_MSB_Long(fin); form_size -= 4;
  858.   DEBUG_LEVEL2 fprintf(stderr,"    ");
  859.   DEBUG_LEVEL2 SET_Print_CHID(chid);
  860.   DEBUG_LEVEL2 fprintf(stderr,"%lx ",form_size);
  861.   DEBUG_LEVEL2 SET_Print_CHID(data);
  862.   if (chid != FORM) SET_TheEnd1("SET: face is not FORM\n");
  863.   while(form_size)
  864.   {
  865.     chid = UTIL_Get_MSB_Long(fin); form_size -= 4;
  866.     size = UTIL_Get_MSB_Long(fin); form_size -= 4;
  867.     DEBUG_LEVEL2 SET_Print_CHID(chid);
  868.     DEBUG_LEVEL2 fprintf(stderr,"%lx ",size);
  869.     form_size -= size;
  870.     if (form_size < 0) form_size = 0;
  871.  
  872.     switch(chid)
  873.     {
  874.       case FACE:
  875.     face_hdr->xsize = UTIL_Get_MSB_UShort(fin);
  876.     face_hdr->ysize = UTIL_Get_MSB_UShort(fin);
  877.     face_hdr->x     = UTIL_Get_MSB_Short(fin);
  878.     face_hdr->y     = UTIL_Get_MSB_Short(fin);
  879.     face_hdr->xoff  = UTIL_Get_MSB_Short(fin);
  880.     face_hdr->yoff  = UTIL_Get_MSB_Short(fin);
  881.     DEBUG_LEVEL2 
  882.     {
  883.   fprintf(stderr,"      FACE size <%ld,%ld> p <%ld,%ld> off <%ld,%ld>\n",
  884.       (LONG)face_hdr->xsize,(LONG)face_hdr->ysize,
  885.       (LONG)face_hdr->x,    (LONG)face_hdr->y,
  886.       (LONG)face_hdr->xoff, (LONG)face_hdr->yoff );
  887.     }
  888.     break;
  889.       case BODY:
  890.     {
  891.       pic = (UBYTE *) 
  892.         malloc( XA_PIC_SIZE(face_hdr->xsize * face_hdr->ysize) );
  893.       if (pic == 0) SET_TheEnd1("SET_Read_BODY: malloc failed\n");
  894.           DEBUG_LEVEL2 fprintf(stderr,"   %ldx%ldx%ld comp=%ld msk=%ld",
  895.                 face_hdr->xsize,face_hdr->ysize,set_imaged,bmhd.compression,
  896.         bmhd.masking);
  897.  
  898.       IFF_Read_BODY(fin,pic,size,
  899.         face_hdr->xsize, face_hdr->ysize, 5,
  900.         (ULONG)(bmhd.compression), (ULONG)(bmhd.masking),set_or_mask);
  901.       form_size = 0; /* body is always last */
  902.       break;
  903.     }
  904.       default: 
  905.     SET_TheEnd1("\nUnknown in Back chunk\n");
  906.     break;
  907.     } /* end of switch */
  908.   } /* end of while */
  909.  DEBUG_LEVEL2 fprintf(stderr,"\n");
  910.  return(pic);
  911. }
  912.  
  913.  
  914. void SET_Free_Stuff()
  915. {
  916.   while(set_back_cur != 0)
  917.   {
  918.     SET_BACK_HDR *tmp;
  919.     tmp = set_back_cur;
  920.     set_back_cur = set_back_cur->next;
  921.     FREE(tmp,0x7000);
  922.   }
  923.   while(set_sset_cur != 0)
  924.   {
  925.     SET_SSET_HDR *tmp;
  926.     ULONG num;
  927.     num = set_sset_cur->face_num;
  928.     if (set_sset_cur->faces != 0) 
  929.     { FREE(set_sset_cur->faces,0x7000); set_sset_cur->faces=0;}
  930.     tmp = set_sset_cur;
  931.     set_sset_cur = set_sset_cur->next;
  932.     FREE(tmp,0x7000);
  933.   }
  934. }
  935.  
  936. void SET_TheEnd1(mess)
  937. UBYTE *mess;
  938. {
  939.   SET_Free_Stuff();
  940.   TheEnd1(mess);
  941. }
  942.  
  943. void SET_TheEnd()
  944. {
  945.   SET_Free_Stuff();
  946.   TheEnd();
  947. }
  948.  
  949. void SET_Read_Sound_IFF(fin)
  950. FILE *fin;
  951. {
  952.   ULONG chid,data;
  953.   LONG size,form_size;
  954.  
  955.   chid = UTIL_Get_MSB_Long(fin);
  956.   form_size = UTIL_Get_MSB_Long(fin);
  957.   DEBUG_LEVEL2 fprintf(stderr,"    FORM %lx ",form_size);
  958.   data = UTIL_Get_MSB_Long(fin); form_size -= 4;
  959.   DEBUG_LEVEL2 SET_Print_CHID(data);
  960.   if (chid != FORM) SET_TheEnd1("SET: sound is not FORM\n");
  961.   while(form_size)
  962.   {
  963.     ULONG d;
  964.     chid = UTIL_Get_MSB_Long(fin); form_size -= 4;
  965.     size = UTIL_Get_MSB_Long(fin); form_size -= 4;
  966.     DEBUG_LEVEL2 SET_Print_CHID(data);
  967.     DEBUG_LEVEL2 fprintf(stderr," %lx ",size);
  968.     form_size -= size;
  969.     if (form_size < 0) form_size = 0;
  970.     switch(chid)
  971.     {
  972.       case BODY:
  973.     form_size = 0; /* last chunk */
  974.       case VHDR:
  975.       case ANNO:
  976.       case CHAN:
  977.     while( (size--) && !feof(fin) ) d = fgetc(fin);
  978.     break;
  979.       default: 
  980.     SET_Print_CHID(chid); SET_TheEnd1("\nUnknown in SOUND chunk\n");
  981.     break;
  982.     } /* end of switch */
  983.   } /* end of while */
  984.  DEBUG_LEVEL2 fprintf(stderr,"\n");
  985. }
  986.  
  987. SET_FRAM_HDR *SET_Init_FRAM_HDRS(num)
  988. ULONG num;
  989. {
  990.   SET_FRAM_HDR *tmp_fram;
  991.   ULONG i;
  992.  
  993.   tmp_fram = (SET_FRAM_HDR *)malloc(num * sizeof(SET_FRAM_HDR) );
  994.   if (tmp_fram == 0) SET_TheEnd1("SET_Init_Fram_HDR: malloc failed");
  995.  
  996.   for(i=0; i<num; i++)
  997.   {
  998.     tmp_fram[i].time     = 0xffffffff;
  999.     tmp_fram[i].cm_act   = 0;
  1000.     tmp_fram[i].pms_act  = 0;
  1001.     tmp_fram[i].back_act = 0;
  1002.     tmp_fram[i].cm_hdr   = 0;
  1003.     tmp_fram[i].pms_hdr  = 0;
  1004.   }
  1005.   return(tmp_fram);
  1006. }
  1007.  
  1008.   
  1009. void SET_Add_CHDR(chdr,fram_num)
  1010. XA_CHDR *chdr;
  1011. ULONG fram_num;
  1012. {
  1013.   SET_FRAM_HDR *fram_hdr;
  1014.  
  1015.   if (fram_num > set_fram_num)
  1016.   {
  1017.     fprintf(stderr,"SET_Add_CHDR: invalid frame %lx\n", fram_num);
  1018.     return;
  1019.   }
  1020.   fram_hdr = &set_frames[fram_num];
  1021.   if (fram_hdr->cm_hdr != 0)
  1022.   {
  1023.     DEBUG_LEVEL2 fprintf(stderr,"SET_Add_CHDR: duplicate cmap warning\n");
  1024.   }
  1025.   fram_hdr->cm_hdr = chdr;
  1026. }
  1027.  
  1028. void SET_Add_BACK(fram_num,back_act,chdr)
  1029. ULONG fram_num;
  1030. XA_ACTION *back_act;
  1031. XA_CHDR *chdr;
  1032. {
  1033.   SET_FRAM_HDR *fram_hdr;
  1034.  
  1035.   if (fram_num > set_fram_num)
  1036.   {
  1037.     fprintf(stderr,"SET_Add_BACK: invalid frame %lx\n", fram_num);
  1038.     return;
  1039.   }
  1040.   fram_hdr = &set_frames[fram_num];
  1041.   if (fram_hdr->back_act != 0)
  1042.     fprintf(stderr,"SET_Add_BACK: duplicate back err\n");
  1043.   fram_hdr->back_act = back_act;
  1044.  
  1045.       /* if no CMAP for this frame add the back's */
  1046.   if (fram_hdr->cm_hdr == 0) SET_Add_CHDR(chdr,fram_num);
  1047.  
  1048. }
  1049.  
  1050. void SET_Add_TIME(fram_num,fram_time)
  1051. ULONG fram_num,fram_time;
  1052. {
  1053.   SET_FRAM_HDR *fram_hdr;
  1054.   if (fram_num > set_fram_num) 
  1055.   {
  1056.     fprintf(stderr,"SET_Add_TIME: invalid fram_num %lx\n",fram_num);
  1057.     return;
  1058.   }
  1059.   fram_hdr = &set_frames[fram_num]; 
  1060.   fram_hdr->time = set_time;
  1061. }
  1062.  
  1063.  
  1064. /*
  1065.  *
  1066.  */
  1067. void SET_Add_SETTER(anim_hdr,fram_num,xpback,ypback,
  1068.         xpface,ypface,face_act,depth)
  1069. XA_ANIM_HDR *anim_hdr;
  1070. ULONG fram_num;
  1071. ULONG xpback,ypback;
  1072. ULONG xpface,ypface;
  1073. XA_ACTION *face_act;
  1074. ULONG depth;
  1075. {
  1076.   ACT_MAPPED_HDR *face_map_hdr;
  1077.   SET_FRAM_HDR *fram_hdr;
  1078.   ACT_SETTER_HDR *tmp_pms,*cur_pms;
  1079.   XA_ACTION *act;
  1080.  
  1081.   if (fram_num > set_fram_num) 
  1082.   {
  1083.     fprintf(stderr,"SET_Add_SETTER: invalid fram_num %lx\n",fram_num);
  1084.     return;
  1085.   }
  1086.   fram_hdr = &set_frames[fram_num]; 
  1087.   face_map_hdr = (ACT_MAPPED_HDR *) face_act->data;
  1088.  
  1089.   act = ACT_Get_Action(anim_hdr);
  1090.  
  1091.  
  1092.   tmp_pms = (ACT_SETTER_HDR *)malloc(sizeof(ACT_SETTER_HDR));
  1093.   if (tmp_pms == 0) SET_TheEnd1("SET_Add_SETTER: malloc failed");
  1094.  
  1095.   act->type = ACT_SETTER;
  1096.   act->data = (UBYTE *)tmp_pms;
  1097.  
  1098.   tmp_pms->work = work_act;
  1099.   tmp_pms->xpback = xpback;
  1100.   tmp_pms->ypback = ypback;
  1101.   tmp_pms->xface = face_map_hdr->xsize;
  1102.   tmp_pms->yface = face_map_hdr->ysize;
  1103.   tmp_pms->xpface = xpface;
  1104.   tmp_pms->ypface = ypface;
  1105.   tmp_pms->depth = depth;
  1106.   tmp_pms->face = face_act;
  1107.   tmp_pms->back = 0;
  1108.   tmp_pms->xback = 0;
  1109.   tmp_pms->yback = 0;
  1110.  
  1111.    /* if this is the 1st one. */
  1112.   if (fram_hdr->pms_hdr == 0)  /* 1st one */
  1113.   {
  1114.     fram_hdr->pms_hdr = tmp_pms;
  1115.     tmp_pms->next = 0;
  1116.     fram_hdr->pms_act = act;
  1117.     return;
  1118.   }
  1119.   /* if 1st one is of less or equal depth */
  1120.   if (fram_hdr->pms_hdr->depth <= depth)
  1121.   {
  1122.     tmp_pms->next = fram_hdr->pms_hdr;
  1123.     fram_hdr->pms_hdr = tmp_pms;
  1124.     fram_hdr->pms_act = act;  /* keep act current */
  1125.     return;
  1126.   }
  1127.  
  1128.   cur_pms = fram_hdr->pms_hdr;
  1129.   while(cur_pms != 0)
  1130.   {
  1131.     /*  there isn't a next one */
  1132.     if (cur_pms->next == 0)
  1133.     {
  1134.       tmp_pms->next = 0;
  1135.       cur_pms->next = tmp_pms;
  1136.       return;
  1137.     }
  1138.      /* if the next one's depth is <= then put here */
  1139.     if (cur_pms->next->depth <= depth)
  1140.     {
  1141.       tmp_pms->next = cur_pms->next;
  1142.       cur_pms->next = tmp_pms;
  1143.       return;
  1144.     }
  1145.     cur_pms = cur_pms->next;
  1146.   }
  1147.  
  1148. }
  1149.  
  1150. void SET_Extract_Directory(dname,cname)
  1151. UBYTE *dname,*cname;
  1152. {
  1153.  ULONG i,j;
  1154.  
  1155.  i = 0;
  1156.  while( (dname[i] != ':') && (i < 256) && (dname[i] != 0) ) i++;
  1157.  if ((dname[i]==0) || (i >= 256)) SET_TheEnd1("SET_Extract: error 1\n");
  1158.  
  1159.  i++; /* skip over : */
  1160.  j = 0;
  1161.  while( (dname[i] != 0) && (i < 256) )
  1162.  {
  1163.    dname[j] = dname[i]; i++; j++;
  1164.  }
  1165.  if (i >= 256) SET_TheEnd1("SET_Extract: error 2\n");
  1166.  dname[j] = '/'; j++;
  1167.  
  1168.  i = 0;
  1169.  while( (cname[i] != 0) && (i<32) ) 
  1170.  {
  1171.    dname[j] = cname[i]; i++; j++;
  1172.  }
  1173.  if (i >= 32) SET_TheEnd1("SET_Extract: error 3\n");
  1174.  dname[j] = 0;
  1175. }
  1176.  
  1177. void SET_Modify_Directory(dname,flag)
  1178. char dname[];
  1179. ULONG flag;
  1180. {
  1181.   int d = (int)dname[0];
  1182.   if (flag == 0)  /* flip upper/lower on 1st char */
  1183.   {
  1184.     if (isupper(d) ) dname[0] = (char)tolower(d);
  1185.     else dname[0] = (char)toupper(d);
  1186.   }
  1187. }
  1188.  
  1189.